const { app } = require("egg-mock");

function checktoken(){
    return async function(ctx,next){
        try{
            let token=ctx.request.header.token;
            let decode=ctx.app.jwt.verify(token,ctx.app.config.jwt.secret);
            if(decode){
                await next();
            }else{
                ctx.body={
                    code:404,
                    msg:'错误',
                }
            }
        }catch(e){
            ctx.body={
                code:405,
                msg:'无权访问',
                data:e
            }
        }
        // eyJhbGciOiJIUzI1NiJ9.YWRtaW4.L1HFmElT-E-OXAUbyI9D2dyy3HHZyanz3XSQWht-NaA
        // eyJhbGciOiJIUzI1NiJ9.YWRtaW4.fM90A2TVRQTiojkfPyf6k55RnkUIsIZl_3VyVRP5HSM
        
    }
}

module.exports=checktoken;
